<?php
/*****************************************************
 * File name: Version.php
 * Create date: 2019/03/28
 * Author: liuyue
 * Description: 版本模块cgi
 *****************************************************/

namespace Ctrl;
use Model;

use Lib;

class Version extends Lib\Base\Ctrl
{

    /**
     * 版本视图
     */
    public function index()
    {
        //获取版本集合数据
        $db = Lib\Db\DbModel::init(); // 构造方法，线上自动切换

        $versionInfo = $db->table('tbversion')->limit(10)->select();

        foreach ($versionInfo as &$arr){
            $arr['isCurrent'] = $arr['isCurrent'] == 1 ?"是":"否";
        }

        $this->assign('versionInfo',$versionInfo);
        $this->display('Admin/Version/index');
    }

    /**
     * 切换数据版本
     */
    public function switchVersion()
    {
        $db = Lib\Db\DbModel::init(); // 构造方法，线上自动切换

        if(IS_POST)
        {
            $versionInfo = array(
                'id' => $_POST['id'],
                'versionNumber  '      => $_POST['versionNumber'],
                'isCurrent' => 1,
                'updateTime' => time(),
            );

            $model = new Model\VersionModel();

            if($model->editVersion($versionInfo)){
                $this->ajaxSuccess("切换成功");
            }else{
                $this->ajaxError('切换失败');
            }
        }else{

            //获取版本号
            $versionInfo = $db->table('tbversion')->where(['isCurrent' => 1])->find();

            $this->assign('id', $_GET['id']);
            $this->assign('versionInfo', $versionInfo['versionNumber']);
            $this->display("Admin/Version/switchVersion");
        }
    }

    /**
     * 第一次添加数据库版本
     */
    public function addVersion()
    {
        $db = Lib\Db\DbModel::init(); // 构造方法，线上自动切换

        if(IS_POST)
        {
            //添加输入的版本
            $versionNum = $_POST['versionNum'];
            //版本数据的类型
            $type = $_POST["type"];

            //判断输入的版本
            if(empty($versionNum)){
                $this->ajaxError('数据版本为空');
                return;
            }

            //环境判断
            if (ENV == 'test' && ENVIRONMENT == 'NON_OA') {
                $savePath = APP.'upload/';
            } else {
                $savePath = UPLOADED_PATH;
            }

            $model = new Model\VersionModel();

            //判断是否版本已经存在
            if($model->isExistsVersion($versionNum)){
                //根据版本号查询出版本的主键Id
                $versionDetail = $db->table('tbversion')->where(['versionNumber' => $versionNum])->find();
                //检查是否导入对应的JSON文件
                if($type=="TombaJson"){
                    if(!file_exists( $savePath. 'jsonFiles/'.date("Ymd")."/TombaJson")){
                        $this->ajaxError("请导入对应版本的数据");
                    }
                    //再次点的时候,检查版本状态
                    $checkStstus = $model->getVersionStatus($versionNum);
                    if(2==(int)$checkStstus['status']){      //2还是2,执行更新操作
                        $this->ajaxError($versionNum.'TMOBA版本数据已经存在,确认更新？',array("versionNum"=>$versionNum));
                    }elseif(3==(int)$checkStstus['status']){ //3=>1 [json]
                        //$this->ajaxError($versionNum.'JSON版本数据已经存在,确认更新？',array("versionNum"=>$versionNum));
                        //更新成功后改变文件夹的名称(名称以版本号为命名)
                        $new_name = $savePath. 'jsonFiles/'.$versionNum."/TombaJson/";
                        var_dump($new_name);
                        var_dump($savePath.'jsonFiles/'.date("Ymd"));
                        if(file_exists($new_name)||!file_exists($savePath.'jsonFiles/'.date("Ymd"))){
                            $this->ajaxError("目标文件已存在或原文件不存在");
                        }else{
                            if(rename($savePath.'jsonFiles/'.date("Ymd"),$new_name)){
                                $this->ajaxSuccess("更新到数据库成功");
                            }else{
                                $this->ajaxError("文件夹重命名失败");
                            }
                        }
                    }else{
                        $this->ajaxSuccess($versionNum.'版本数据已存档');
                    }
                }elseif($type=="Json")
                {
                    if(!file_exists( $savePath. 'jsonFiles/'.date("Ymd")."/Json")){
                        $this->ajaxError("请导入对应版本的数据");
                    }
                    //再次点的时候,检查版本状态
                    $checkStstus = $model->getVersionStatus($versionNum);
                    if(2==(int)$checkStstus['status']){ //2=>1
                        //$this->ajaxError($versionNum.'TMOBA版本数据已经存在,确认更新？',array("versionNum"=>$versionNum));
                        //更新成功后改变文件夹的名称(名称以版本号为命名)
                        $new_name = $savePath. 'jsonFiles/'.$versionNum."/Json/";
                        if(file_exists($new_name)){
                            //将里面的内容copy至新目录
                            if(copydir($savePath.'jsonFiles/'.date("Ymd")."/Json",$new_name)){
                                deleteDir($savePath.'jsonFiles/'.date("Ymd"));

                                //读取Json文件里面的数据
                                if(is_dir($savePath.'jsonFiles/'.$versionNum."/Json/")) {
                                    //判断是否有文件
                                    $fileList = my_scandir($savePath . 'jsonFiles/' . $versionNum . "/Json");

                                    //如果为空
                                    if (empty($fileList)) {
                                        $this->ajaxError("未导入数据");
                                    }
                                    foreach ($fileList as $key => $val) {
                                        //依次读取里面的内容
                                        //item.json(判断是否是item.json)
                                        if(strpos($val,"item.json")!==FALSE)
                                        {
                                            // 从文件中读取数据到PHP变量
                                            $json_string = file_get_contents($val);
                                            // 用参数true把JSON字符串强制转成PHP数组
                                            $itemData = json_decode($json_string, true);
                                            //var_dump("--------------Json道具-------------");
                                            //var_dump($itemData);
                                            //var_dump("--------------Json道具---------");
                                        }
                                        //champion.json
                                        if(strpos($val,"champion.json")!==FALSE)
                                        {
                                            // 从文件中读取数据到PHP变量
                                            $json_string = file_get_contents($val);
                                            // 用参数true把JSON字符串强制转成PHP数组
                                            $championData = json_decode($json_string, true);
                                            //var_dump("--------------道具-------------");
                                            //var_dump($itemsData);
                                            //var_dump("--------------道具结束---------");
                                        }
                                        //championFull.json
                                        if(strpos($val,"championFull.json")!==FALSE)
                                        {
                                            // 从文件中读取数据到PHP变量
                                            $json_string = file_get_contents($val);
                                            // 用参数true把JSON字符串强制转成PHP数组
                                            $championFullData = json_decode($json_string, true);
                                            //var_dump("--------------道具-------------");
                                            //var_dump($itemsData);
                                            //var_dump("--------------道具结束---------");
                                        }
                                        // 从文件中读取数据到PHP变量
                                        $json_string = file_get_contents($val);
                                        //获取英雄名称(截取最后一个斜杠后面的内容)
                                        $tempDir = trim(strrchr($val, '/'), '/');
                                        $heroName = substr($tempDir, 0, strrpos($tempDir, "."));
                                        // 用参数true把JSON字符串强制转成PHP数组
                                        $data = json_decode($json_string, true);

                                        //判断是否有如果有的话就添加(从数据库里面查询出信息)
                                        $res = $db->table('tbhero')->where(['heroId' => $data['data'][$heroName]['key'], 'versionId' => $versionDetail['id']])->find();
                                        if (!empty($res)) {
                                            var_dump("更新");
                                            //更新
                                            $a = $db->table('tbhero')->where(['id' => $res['id']], ['versionId' => $res['versionId']])->update([
                                                'name' => $data['data'][$heroName]['name'], 'title' => $data['data'][$heroName]['title'],
                                                'alias' => $data['data'][$heroName]['id'], 'heroId' => $data['data'][$heroName]['key'],
                                                'attack' => $data['data'][$heroName]['info']['attack'], 'defense' => $data['data'][$heroName]['info']['defense'],
                                                'magic' => $data['data'][$heroName]['info']['magic'], 'difficulty' => $data['data'][$heroName]['info']['difficulty'],
                                                'hp' => $data['data'][$heroName]['stats']['hp'], 'hpperlevel' => $data['data'][$heroName]['stats']['hpperlevel'],
                                                'mp' => $data['data'][$heroName]['stats']['mp'], 'mpperlevel' => $data['data'][$heroName]['stats']['mpperlevel'],
                                                'mpperlevel' => $data['data'][$heroName]['stats']['mpperlevel'], 'movespeed' => $data['data'][$heroName]['stats']['movespeed'],
                                                'armor' => $data['data'][$heroName]['stats']['armor'], 'armorperlevel' => $data['data'][$heroName]['stats']['armorperlevel'],
                                                'spellblock' => $data['data'][$heroName]['stats']['spellblock'], 'spellblockperlevel' => $data['data'][$heroName]['stats']['spellblockperlevel'],
                                                'attackrange' => $data['data'][$heroName]['stats']['attackrange'], 'hpregen' => $data['data'][$heroName]['stats']['hpregen'],
                                                'hpregenperlevel' => $data['data'][$heroName]['stats']['hpregenperlevel'], 'mpregen' => $data['data'][$heroName]['stats']['mpregen'],
                                                'mpregenperlevel' => $data['data'][$heroName]['stats']['mpregenperlevel'], 'crit' => $data['data'][$heroName]['stats']['crit'],
                                                'cirtperlevel' => $data['data'][$heroName]['stats']['cirtperlevel'], 'attackdamage' => $data['data'][$heroName]['stats']['attackdamage'],
                                                'attackdamage' => $data['data'][$heroName]['stats']['attackdamage'], 'attackdamageperlevel' => $data['data'][$heroName]['stats']['attackdamageperlevel'],
                                                'attackspeed' => $data['data'][$heroName]['stats']['attackspeed'], 'attackspeedperlevel' => $data['data'][$heroName]['stats']['attackspeedperlevel'],
                                                'allytips' => $data['data'][$heroName]['allytips'][0], 'enemytips' => $data['data'][$heroName]['enemytips'][0],
                                                //版本Id,创建人,创建时间
                                                'versionId' => $versionDetail['id'], 'updateMan' => "default", 'updateTime' => date("Y-m-d H:i:s",time()),
                                            ]);
                                        } else {
                                            var_dump("添加");
                                            //增加
                                            //添加到数据库(英雄称号,英雄Id,攻击力)
                                            $skillRes = $db->table('tbhero')->insert(
                                                [
                                                    'name' => $data['data'][$heroName]['name'], 'title' => $data['data'][$heroName]['title'],
                                                    'alias' => $data['data'][$heroName]['id'], 'heroId' => $data['data'][$heroName]['key'],
                                                    'attack' => $data['data'][$heroName]['info']['attack'], 'defense' => $data['data'][$heroName]['info']['defense'],
                                                    'magic' => $data['data'][$heroName]['info']['magic'], 'difficulty' => $data['data'][$heroName]['info']['difficulty'],
                                                    'hp' => $data['data'][$heroName]['stats']['hp'], 'hpperlevel' => $data['data'][$heroName]['stats']['hpperlevel'],
                                                    'mp' => $data['data'][$heroName]['stats']['mp'], 'mpperlevel' => $data['data'][$heroName]['stats']['mpperlevel'],
                                                    'mpperlevel' => $data['data'][$heroName]['stats']['mpperlevel'], 'movespeed' => $data['data'][$heroName]['stats']['movespeed'],
                                                    'armor' => $data['data'][$heroName]['stats']['armor'], 'armorperlevel' => $data['data'][$heroName]['stats']['armorperlevel'],
                                                    'spellblock' => $data['data'][$heroName]['stats']['spellblock'], 'spellblockperlevel' => $data['data'][$heroName]['stats']['spellblockperlevel'],
                                                    'attackrange' => $data['data'][$heroName]['stats']['attackrange'], 'hpregen' => $data['data'][$heroName]['stats']['hpregen'],
                                                    'hpregenperlevel' => $data['data'][$heroName]['stats']['hpregenperlevel'], 'mpregen' => $data['data'][$heroName]['stats']['mpregen'],
                                                    'mpregenperlevel' => $data['data'][$heroName]['stats']['mpregenperlevel'], 'crit' => $data['data'][$heroName]['stats']['crit'],
                                                    'cirtperlevel' => $data['data'][$heroName]['stats']['cirtperlevel'], 'attackdamage' => $data['data'][$heroName]['stats']['attackdamage'],
                                                    'attackdamage' => $data['data'][$heroName]['stats']['attackdamage'], 'attackdamageperlevel' => $data['data'][$heroName]['stats']['attackdamageperlevel'],
                                                    'attackspeed' => $data['data'][$heroName]['stats']['attackspeed'], 'attackspeedperlevel' => $data['data'][$heroName]['stats']['attackspeedperlevel'],
                                                    'allytips' => $data['data'][$heroName]['allytips'][0], 'enemytips' => $data['data'][$heroName]['enemytips'][0],
                                                    //版本Id,创建人,创建时间
                                                    'versionId' => $versionDetail['id'], 'creater' => "default", 'createTime' => date("Y-m-d H:i:s",time()),
                                                ]);
                                        }

                                        //英雄技能
                                        $spellsRes = $db->table('tbspells')->where(['heroId' => $data['data'][$heroName]['key'], 'versionId' => $versionDetail['id']])->find();
                                        if (!empty($spellsRes)) {
                                            //更新
                                            $db->table('tbspells')->where(['id' => $res['id']], ['versionId' => $res['versionId']])->update([
                                                'cost' => serialize($data['data'][$heroName]['spells']['cost']), 'costburn' =>  $data['data'][$heroName]['spells']['costburn'],
                                                'cooldown' => $data['data'][$heroName]['spells']['cooldown'], 'cooldownburn' =>  $data['data'][$heroName]['spells']['cooldownburn'],
                                                //版本Id,创建人,创建时间
                                                'versionId' => $versionDetail['id'], 'updateMan' => "default", 'updateTime' => date("Y-m-d H:i:s",time()),
                                            ]);

                                        }else{
                                            //添加
                                            $db->table('tbspells')->insert(
                                            [
                                                'cost' => serialize($data['data'][$heroName]['spells']['cost']), 'costburn' =>  $data['data'][$heroName]['spells']['costburn'],
                                                'cooldown' => $data['data'][$heroName]['spells']['cooldown'], 'cooldownburn' =>  $data['data'][$heroName]['spells']['cooldownburn'],
                                                //版本Id,创建人,创建时间
                                                'versionId' => $versionDetail['id'], 'creater' => "default", 'createTime' => date("Y-m-d H:i:s",time()),
                                            ]);
                                        }
                                    }

                                    //英雄道具
                                   //var_dump($itemData['data']);
                                   foreach ($itemData['data'] as $key=>$val)
                                   {
                                       //判断是否有如果有的话就添加(从数据库里面查询出信息)
                                       $res = $db->table('tbitems')->where(['itemId' =>$key, 'versionId' => $versionDetail['id']])->find();
                                       if (!empty($res)) {
                                           //更新到数据库(英雄道具简述,英雄道具出售价,英雄道具总价,道具可合成,道具合成部件版本Id)
                                           $db->table('tbitems')->where(['id' => $res['id']], ['versionId' => $res['versionId']])->update([
                                               'plaintext' => $val['plaintext'], 'sell' => $val['gold']['sell'], 'total' => $val['gold']['total'],
                                               'into' => $val['into'][0], 'from' => $val['from'][0],
                                               //版本Id,创建人,创建时间
                                               'versionId' => $versionDetail['id'], 'updateMan' => "default", 'updateTime' => date("Y-m-d H:i:s",time()),
                                           ]);
                                       }else{
                                           //添加到数据库(英雄名称,英雄中文名,英雄称号,英雄Id,英雄定位,英雄简介，英雄阵营，版本Id)
                                            $db->table('tbitems')->insert(
                                               [
                                                   'itemId' =>$key, 'versionId' => $versionDetail['id'],
                                                   'plaintext' => $val['plaintext'], 'sell'     => $val['gold']['sell'], 'total' => $val['gold']['total'],
                                                   'into' => $val['into'][0], 'from' => $val['from'][0],
                                                   //版本Id,创建人,创建时间
                                                   'versionId' => $versionDetail['id'], 'creater' => "default", 'createTime' => date("Y-m-d H:i:s",time()),
                                               ]);
                                       }
                                   }
                                    var_dump($championFullData);
                                   //英雄皮肤
                                   /*if(!empty( $championFullData))
                                   {
                                       var_dump($championFullData);
                                   }*/


                                }
                            }else{
                                $this->ajaxError('没有导入数据，请导入数据');
                            }
                            if($model->editVersionStatus($versionDetail['id'],1)){
                                $this->ajaxSuccess("更新到数据库成功");
                            }else{
                                $this->ajaxSuccess("更新到数据库失败");
                            }
                        }else{
                            if(rename($savePath.'jsonFiles/'.date("Ymd")."/Json",$new_name)&&rmdir($savePath.'jsonFiles/'.date("Ymd"))){
                                //读取Json文件里面的数据
                                if(is_dir($savePath.'jsonFiles/'.$versionNum."/Json/")){
                                    //判断是否有文件
                                    $fileList = my_scandir($savePath.'jsonFiles/'.$versionNum."/Json");

                                    foreach ($fileList as $key=>$val)
                                    {
                                        //依次读取里面的内容
                                        // 从文件中读取数据到PHP变量
                                        $json_string = file_get_contents($val);
                                        //获取英雄名称(截取最后一个斜杠后面的内容)
                                        $tempDir = trim(strrchr($val, '/'),'/');
                                        $heroName = substr($tempDir,0,strrpos($tempDir,"."));
                                        // 用参数true把JSON字符串强制转成PHP数组
                                        $data = json_decode($json_string, true);
                                        //var_dump($data['data'][$heroName]);
                                        //英雄名称
                                        var_dump($data['data'][$heroName]['id']);
                                        //英雄Id
                                        var_dump($data['data'][$heroName]['key']);
                                        //攻击力
                                        var_dump($data['data'][$heroName]['info']['attack']);
                                        //防御力
                                        var_dump($data['data'][$heroName]['info']['defense']);
                                        //魔法
                                        var_dump($data['data'][$heroName]['info']['magic']);
                                        //难度
                                        var_dump($data['data'][$heroName]['info']['difficulty']);
                                        //初始生命
                                        var_dump($data['data'][$heroName]['stats']['hp']);
                                        //生命成长
                                        var_dump($data['data'][$heroName]['stats']['hpperlevel']);
                                        //初始魔法
                                        var_dump($data['data'][$heroName]['stats']['mp']);
                                        //魔法成长
                                        var_dump($data['data'][$heroName]['stats']['mpperlevel']);
                                        //移动速度
                                        var_dump($data['data'][$heroName]['stats']['movespeed']);
                                        //初始护甲
                                        var_dump($data['data'][$heroName]['stats']['armor']);
                                        //护甲成长
                                        var_dump($data['data'][$heroName]['stats']['armorperlevel']);
                                        //初始魔抗
                                        var_dump($data['data'][$heroName]['stats']['spellblock']);
                                        //魔抗成长
                                        var_dump($data['data'][$heroName]['stats']['spellblockperlevel']);
                                        //攻击范围
                                        var_dump($data['data'][$heroName]['stats']['attackrange']);
                                        //生命回复
                                        var_dump($data['data'][$heroName]['stats']['hpregen']);
                                        //生命回复成长
                                        var_dump($data['data'][$heroName]['stats']['hpregenperlevel']);
                                        //魔法回复
                                        var_dump($data['data'][$heroName]['stats']['mpregen']);
                                        //魔法回复成长
                                        var_dump($data['data'][$heroName]['stats']['mpregenperlevel']);
                                        //初始暴击
                                        var_dump($data['data'][$heroName]['stats']['crit']);
                                        //暴击成长
                                        var_dump($data['data'][$heroName]['stats']['cirtperlevel']);
                                        //初始伤害
                                        var_dump($data['data'][$heroName]['stats']['attackdamage']);
                                        //伤害成长
                                        var_dump($data['data'][$heroName]['stats']['attackdamageperlevel']);
                                        //初始攻击速度
                                        var_dump($data['data'][$heroName]['stats']['attackspeed']);
                                        //攻击速度成长
                                        var_dump($data['data'][$heroName]['stats']['attackspeedperlevel']);

                                        //判断是否有如果有的话就添加(从数据库里面查询出信息)
                                        $res = $db->table('tbhero')->where(['alias' => $data['data'][$heroName]['id']])->find();
                                        if(!empty($res)){
                                            //更新
                                            $db->table('tbhero')->where(['id' => $res['id']],['versionId'=> $res['versionId']])->update( [
                                                'name' => $data['data'][$heroName]['name'], 'title' =>$data['data'][$heroName]['title'],
                                                'alias' => $data['data'][$heroName]['id'], 'heroId' =>$data['data'][$heroName]['key'],
                                                'attack' => $data['data'][$heroName]['info']['attack'],'defense'=>$data['data'][$heroName]['info']['defense'],
                                                'magic' => $data['data'][$heroName]['info']['magic'], 'difficulty' => $data['data'][$heroName]['info']['difficulty'],
                                                'hp' => $data['data'][$heroName]['stats']['hp'], 'hpperlevel' => $data['data'][$heroName]['stats']['hpperlevel'],
                                                'mp' => $data['data'][$heroName]['stats']['mp'], 'mpperlevel' => $data['data'][$heroName]['stats']['mpperlevel'],
                                                'mpperlevel' => $data['data'][$heroName]['stats']['mpperlevel'], 'movespeed' => $data['data'][$heroName]['stats']['movespeed'],
                                                'armor' => $data['data'][$heroName]['stats']['armor'], 'armorperlevel' => $data['data'][$heroName]['stats']['armorperlevel'],
                                                'spellblock' => $data['data'][$heroName]['stats']['spellblock'], 'spellblockperlevel' => $data['data'][$heroName]['stats']['spellblockperlevel'],
                                                'attackrange' => $data['data'][$heroName]['stats']['attackrange'], 'hpregen' => $data['data'][$heroName]['stats']['hpregen'],
                                                'hpregenperlevel' => $data['data'][$heroName]['stats']['hpregenperlevel'], 'mpregen' => $data['data'][$heroName]['stats']['mpregen'],
                                                'mpregenperlevel' => $data['data'][$heroName]['stats']['mpregenperlevel'], 'crit' => $data['data'][$heroName]['stats']['crit'],
                                                'cirtperlevel' => $data['data'][$heroName]['stats']['cirtperlevel'], 'attackdamage' => $data['data'][$heroName]['stats']['attackdamage'],
                                                'attackdamage' => $data['data'][$heroName]['stats']['attackdamage'], 'attackdamageperlevel' => $data['data'][$heroName]['stats']['attackdamageperlevel'],
                                                'attackspeed' => $data['data'][$heroName]['stats']['attackspeed'], 'attackspeedperlevel' => $data['data'][$heroName]['stats']['attackspeedperlevel'],
                                                'allytips' => $data['data'][$heroName]['allytips'][0], 'enemytips' => $data['data'][$heroName]['enemytips'][0],
                                                //版本Id,创建人,创建时间
                                                'versionId' => $versionDetail['id'], 'updateMan' => "default", 'updateTime' => date("Y-m-d H:i:s",time()),
                                            ]);
                                        }else{
                                           //增加
                                           //添加到数据库(英雄称号,英雄Id,攻击力)
                                           $db->table('tbhero')->insert(
                                                  [
                                                    'name' => $data['data'][$heroName]['name'], 'title' =>$data['data'][$heroName]['title'],
                                                    'alias' => $data['data'][$heroName]['id'], 'heroId' =>$data['data'][$heroName]['key'],
                                                   'attack' => $data['data'][$heroName]['info']['attack'],'defense'=>$data['data'][$heroName]['info']['defense'],
                                                   'magic' => $data['data'][$heroName]['info']['magic'], 'difficulty' => $data['data'][$heroName]['info']['difficulty'],
                                                   'hp' => $data['data'][$heroName]['stats']['hp'], 'hpperlevel' => $data['data'][$heroName]['stats']['hpperlevel'],
                                                   'mp' => $data['data'][$heroName]['stats']['mp'], 'mpperlevel' => $data['data'][$heroName]['stats']['mpperlevel'],
                                                   'mpperlevel' => $data['data'][$heroName]['stats']['mpperlevel'], 'movespeed' => $data['data'][$heroName]['stats']['movespeed'],
                                                   'armor' => $data['data'][$heroName]['stats']['armor'], 'armorperlevel' => $data['data'][$heroName]['stats']['armorperlevel'],
                                                   'spellblock' => $data['data'][$heroName]['stats']['spellblock'], 'spellblockperlevel' => $data['data'][$heroName]['stats']['spellblockperlevel'],
                                                   'attackrange' => $data['data'][$heroName]['stats']['attackrange'], 'hpregen' => $data['data'][$heroName]['stats']['hpregen'],
                                                   'hpregenperlevel' => $data['data'][$heroName]['stats']['hpregenperlevel'], 'mpregen' => $data['data'][$heroName]['stats']['mpregen'],
                                                   'mpregenperlevel' => $data['data'][$heroName]['stats']['mpregenperlevel'], 'crit' => $data['data'][$heroName]['stats']['crit'],
                                                   'cirtperlevel' => $data['data'][$heroName]['stats']['cirtperlevel'], 'attackdamage' => $data['data'][$heroName]['stats']['attackdamage'],
                                                   'attackdamage' => $data['data'][$heroName]['stats']['attackdamage'], 'attackdamageperlevel' => $data['data'][$heroName]['stats']['attackdamageperlevel'],
                                                   'attackspeed' => $data['data'][$heroName]['stats']['attackspeed'], 'attackspeedperlevel' => $data['data'][$heroName]['stats']['attackspeedperlevel'],
                                                   'allytips' => $data['data'][$heroName]['allytips'][0], 'enemytips' => $data['data'][$heroName]['enemytips'][0],
                                                   //版本Id
                                                   'versionId' => $versionDetail['id'],'creater' => "default", 'createTime' => date("Y-m-d H:i:s",time()),
                                           ]);
                                        }
                                    }
                                }else{
                                    $this->ajaxError('没有导入数据，请导入数据');
                                }
                                $this->ajaxSuccess("更新到数据库成功");
                            }else{
                                $this->ajaxError("文件夹重命名失败");
                            }
                        }
                    }elseif(3==(int)$checkStstus['status']){  //3还是3,执行更新操作
                        $this->ajaxError($versionNum.'JSON版本数据已经存在,确认更新？',array("versionNum"=>$versionNum));
                    }else{
                        $this->ajaxSuccess($versionNum.'版本数据已存档');
                    }
                }

            }else{
                    //版本不存在,第一次直接读取Json文件里面的数据

                    $db = Lib\Db\DbModel::init(); // 构造方法，线上自动切换
                    //实例化
                    $model = new Model\VersionModel();

                    //获取版本号状态
                    $resStatus = $model->getVersionStatus($versionNum);

                    $dir = empty($_GET['dir']) ? 'jsonFiles/'.date("Ymd")."/".$type.'/' : 'Uploads/' . $_GET['dir'];

                    //上面的操作
                    if($type=="TombaJson"){
                        //读取Json文件里面的数据
                        if(is_dir($savePath.$dir)){
                            //判断是否有文件
                            $fileList = my_scandir($savePath.$dir);
                            //第一次添加版本
                            if($model->addVersion($versionNum)) {
                                //根据版本号查询出版本的主键Id
                                $versionDetail = $db->table('tbversion')->where(['versionNumber' => $versionNum])->find();
                            }

                            foreach ($fileList as $key=>$val)
                            {
                                //skins.json(判断是否是skins.json)
                                if(strpos($val,"skins.json")!==FALSE)
                                {
                                    // 从文件中读取数据到PHP变量
                                    $json_string = file_get_contents($val);
                                    // 用参数true把JSON字符串强制转成PHP数组
                                    $skinsData = json_decode($json_string, true);
                                    //var_dump("--------------皮肤-------------");
                                    //var_dump($itemsData);
                                    //var_dump("--------------皮肤结束---------");
                                }
                                //items.json
                                if(strpos($val,"items.json")!==FALSE)
                                {
                                    // 从文件中读取数据到PHP变量
                                    $json_string = file_get_contents($val);
                                    // 用参数true把JSON字符串强制转成PHP数组
                                    $itemsData = json_decode($json_string, true);
                                    //var_dump("--------------道具-------------");
                                    //var_dump($itemsData);
                                    //var_dump("--------------道具结束---------");
                                }

                                //依次读取里面的内容
                                // 从文件中读取数据到PHP变量
                                $json_string = file_get_contents($val);
                                // 用参数true把JSON字符串强制转成PHP数组
                                $data = json_decode($json_string, true);

                                //英雄名称
                                //var_dump($data['title']);
                                //英雄称号
                                //var_dump($data['name']);
                                //英文名
                                //var_dump($data['alias']);
                                //英雄Id
                                //var_dump($data['id']);
                                //英雄定位
                                //var_dump($data['roles']);
                                //英雄故事
                                //var_dump($data['shortBio']);
                                //英雄被动技能
                                //var_dump($data['passive']['name']);
                                //英雄被动技能描述
                                //var_dump($data['passive']['description']);
                                //英雄被动技能图标
                                //var_dump($data['passive']['abilityVideoImagePath']);
                                //英雄被动技能视频
                                //var_dump($data['passive']['abilityVideoPath']);

                                //英雄主动技能
                                //遍历里面的内容
                                foreach ($data['spells'] as $key=>$val)
                                {

                                    //添加到数据库(英雄Id,技能类型-被动qwer,技能名称,技能描述,技能图标路径,技能视频路径，技能效果)
                                    $db->table('tbspells')->insert(
                                        ['heroId' => $data['id'],'spellKey' => $val['spellKey'],
                                            'name' => $val['name'],'description'=>  $val['description'],'abilityIconPath' =>$val['abilityIconPath'],
                                            'abilityVideoPath' =>$val['abilityIconPath'],'dynamicDescription' =>$val['dynamicDescription'],
                                            'versionId' => $versionDetail['id'], 'creater' => "default",
                                            'createTime' => date("Y-m-d H:i:s",time()),
                                        ]);
                                }

                                //英雄皮肤
                                foreach ($data['skins'] as $key=>$val)
                                {
                                    //添加到数据库(英雄Id,英雄名称,英雄称号,皮肤名称,皮肤Id,炫彩，炫彩皮肤从属,皮肤标记经典史诗传说等,皮肤描述)
                                    $skillRes = $db->table('tbskins')->insert(
                                        ['heroId' => $data['id'],'heroName' => $data['title'],
                                        'heroTitle' => $data['name'],
                                        'emblems' => $val['emblems'][0]['name'],'description' =>$val['description'],
                                        'versionId' => $versionDetail['id'], 'creater' => "default",
                                        'createTime' => date("Y-m-d H:i:s",time()),
                                       ]);
                                }

                                //添加到数据库(英雄名称,英雄中文名,英雄称号,英雄Id,英雄定位,英雄简介，英雄阵营，版本Id)
                                $HeroRes = $db->table('tbhero')->insert(
                                    ['title' =>$data['title'], 'alias' =>$data['alias'],
                                        'name'=>$data['name'], 'heroId'=>$data['id'],
                                        'roles'=>$data['roles'][0], 'shortBio'=>$data['shortBio'],
                                        'camp'=>"艾欧尼亚", 'versionId'=>$versionDetail['id'],
                                        'creater' => "default", 'createTime' => date("Y-m-d H:i:s",time()),
                                    ]
                                );


                            }
                            //英雄道具
                            if(!empty($itemsData))
                            {
                                foreach ($itemsData as $key=>$val)
                                {
                                    //道具名称
                                    //var_dump($val['name']);
                                    //道具Id
                                    //var_dump($val['id']);
                                    //道具图片
                                    //var_dump($val['iconPath']);
                                    //道具价格
                                    //var_dump($val['price']);
                                    //道具描述
                                    //var_dump($val['description']);
                                    //道具从属地图
                                    //var_dump($val['mapStringIdInclusions']);
                                    //适应英雄
                                    //var_dump(1);
                                    //道具标签
                                    //var_dump("哈哈");
                                    //道具所属类型
                                    //var_dump("哈哈");

                                    //添加到数据库()
                                    $itemsRes = $db->table('tbitems')->insert(
                                        ['name' =>$val['name'], 'itemId' =>$val['id'],
                                            'iconPath'=>$val['iconPath'], 'price'=>$val['price'],
                                            'description'=>$val['description'], 'mapId'=>"{1,2,3}",
                                            'versionId'=>$versionDetail['id'],
                                            'creater' => "default", 'createTime' => date("Y-m-d H:i:s",time()),
                                        ]
                                    );
                                }
                            }

                            /*if($HeroRes&&$skillRes){
                                $this->ajaxSuccess("添加成功");
                            }else{
                                $this->ajaxSuccess("添加失败");
                            }*/

                        }else{
                            $this->ajaxError('没有导入数据，请导入数据');
                        }

                        //改变版本状态
                        try {
                            $db->begin();
                            //检查状态,如果是0->2,3->1
                            if(3==(int)$resStatus['status'])
                            {
                                $db->table('tbversion')->where(['versionNumber' => $versionNum])->update(['status' => 1]);
                            }else{
                                $db->table('tbversion')->where(['versionNumber' => $versionNum])->update(['status' => 2]);
                            }
                            $db->commit();
                            //更新成功后改变文件夹的名称(名称以版本号为命名)
                            $new_name = $savePath. 'jsonFiles/'.$versionNum;
                            if(file_exists($new_name)||!file_exists($savePath.$dir)){
                                $this->ajaxError("目标文件已存在或原文件不存在");
                            }else{
                                if(rename($savePath.'jsonFiles/'.date("Ymd"),$new_name)){
                                    $this->ajaxSuccess("更新到数据库成功");
                                }else{
                                    $this->ajaxError("文件夹重命名失败");
                                }
                            }
                        } catch (\Exception $e) {
                            $db->rollBack();
                            $this->ajaxSuccess("更新到数据库失败");
                        }

                    }elseif($type=="Json"){

                        //读取Json文件里面的数据
                        if(is_dir($savePath.$dir)){
                            //判断是否有文件
                            $fileList = my_scandir($savePath.$dir);
                            //第一次添加版本
                            if($model->addVersion($versionNum)) {
                                //根据版本号查询出版本的主键Id
                                $versionDetail = $db->table('tbversion')->where(['versionNumber' => $versionNum])->find();
                            }
                            foreach ($fileList as $key=>$val)
                            {
                                //依次读取里面的内容
                                //champion.json(champion.json)
                                if(strpos($val,"champion.json")!==FALSE)
                                {
                                    // 从文件中读取数据到PHP变量
                                    $json_string = file_get_contents($val);
                                    // 用参数true把JSON字符串强制转成PHP数组
                                    $championData = json_decode($json_string, true);
                                    //var_dump("--------------皮肤-------------");
                                    //var_dump($itemsData);
                                    //var_dump("--------------皮肤结束---------");
                                }
                                //item.json
                                if(strpos($val,"item.json")!==FALSE)
                                {
                                    // 从文件中读取数据到PHP变量
                                    $json_string = file_get_contents($val);
                                    // 用参数true把JSON字符串强制转成PHP数组
                                    $itemData = json_decode($json_string, true);
                                    //var_dump("--------------道具-------------");
                                    //var_dump($itemsData);
                                    //var_dump("--------------道具结束---------");
                                }
                                //championFull.json
                                if(strpos($val,"championFull.json")!==FALSE)
                                {
                                    // 从文件中读取数据到PHP变量
                                    $json_string = file_get_contents($val);
                                    // 用参数true把JSON字符串强制转成PHP数组
                                    $championFullData = json_decode($json_string, true);
                                    //var_dump("--------------道具-------------");
                                    //var_dump($itemsData);
                                    //var_dump("--------------道具结束---------");
                                }

                                // 从文件中读取数据到PHP变量
                                $json_string = file_get_contents($val);

                                //获取英雄名称(截取最后一个斜杠后面的内容)
                                $tempDir = trim(strrchr($val, '/'),'/');
                                $heroName = substr($tempDir,0,strrpos($tempDir,"."));
                                // 用参数true把JSON字符串强制转成PHP数组
                                $data = json_decode($json_string, true);

                                //判断是否有如果有的话就添加(从数据库里面查询出信息)
                                $res = $db->table('tbhero')->where(['alias' => $data['data'][$heroName]['id']])->find();
                                if(!empty($res)){
                                    //更新
                                    var_dump("更新");
                                    $db->table('tbhero')->where(['id' => $res['id']],['versionId'=> $res['versionId']])->update( [
                                        'name' => $data['data'][$heroName]['name'], 'title' =>$data['data'][$heroName]['title'],
                                        'alias' => $data['data'][$heroName]['id'], 'heroId' =>$data['data'][$heroName]['key'],
                                        'attack' => $data['data'][$heroName]['info']['attack'],'defense'=>$data['data'][$heroName]['info']['defense'],
                                        'magic' => $data['data'][$heroName]['info']['magic'], 'difficulty' => $data['data'][$heroName]['info']['difficulty'],
                                        'hp' => $data['data'][$heroName]['stats']['hp'], 'hpperlevel' => $data['data'][$heroName]['stats']['hpperlevel'],
                                        'mp' => $data['data'][$heroName]['stats']['mp'], 'mpperlevel' => $data['data'][$heroName]['stats']['mpperlevel'],
                                        'mpperlevel' => $data['data'][$heroName]['stats']['mpperlevel'], 'movespeed' => $data['data'][$heroName]['stats']['movespeed'],
                                        'armor' => $data['data'][$heroName]['stats']['armor'], 'armorperlevel' => $data['data'][$heroName]['stats']['armorperlevel'],
                                        'spellblock' => $data['data'][$heroName]['stats']['spellblock'], 'spellblockperlevel' => $data['data'][$heroName]['stats']['spellblockperlevel'],
                                        'attackrange' => $data['data'][$heroName]['stats']['attackrange'], 'hpregen' => $data['data'][$heroName]['stats']['hpregen'],
                                        'hpregenperlevel' => $data['data'][$heroName]['stats']['hpregenperlevel'], 'mpregen' => $data['data'][$heroName]['stats']['mpregen'],
                                        'mpregenperlevel' => $data['data'][$heroName]['stats']['mpregenperlevel'], 'crit' => $data['data'][$heroName]['stats']['crit'],
                                        'cirtperlevel' => $data['data'][$heroName]['stats']['cirtperlevel'], 'attackdamage' => $data['data'][$heroName]['stats']['attackdamage'],
                                        'attackdamage' => $data['data'][$heroName]['stats']['attackdamage'], 'attackdamageperlevel' => $data['data'][$heroName]['stats']['attackdamageperlevel'],
                                        'attackspeed' => $data['data'][$heroName]['stats']['attackspeed'], 'attackspeedperlevel' => $data['data'][$heroName]['stats']['attackspeedperlevel'],
                                        'allytips' => $data['data'][$heroName]['allytips'][0], 'enemytips' => $data['data'][$heroName]['enemytips'][0],
                                        //版本Id,创建人,创建时间
                                        'versionId' => $versionDetail['id'], 'updateMan' => "default", 'updateTime' => date("Y-m-d H:i:s",time()),
                                    ]);
                                }else{
                                    //增加
                                    //更新
                                    var_dump("增加");
                                    //添加到数据库(英雄称号,英雄Id,攻击力)
                                    $db->table('tbhero')->insert(
                                        [
                                            'name' => $data['data'][$heroName]['name'], 'title' =>$data['data'][$heroName]['title'],
                                            'alias' => $data['data'][$heroName]['id'], 'heroId' =>$data['data'][$heroName]['key'],
                                            'attack' => $data['data'][$heroName]['info']['attack'],'defense'=>$data['data'][$heroName]['info']['defense'],
                                            'magic' => $data['data'][$heroName]['info']['magic'], 'difficulty' => $data['data'][$heroName]['info']['difficulty'],
                                            'hp' => $data['data'][$heroName]['stats']['hp'], 'hpperlevel' => $data['data'][$heroName]['stats']['hpperlevel'],
                                            'mp' => $data['data'][$heroName]['stats']['mp'], 'mpperlevel' => $data['data'][$heroName]['stats']['mpperlevel'],
                                            'mpperlevel' => $data['data'][$heroName]['stats']['mpperlevel'], 'movespeed' => $data['data'][$heroName]['stats']['movespeed'],
                                            'armor' => $data['data'][$heroName]['stats']['armor'], 'armorperlevel' => $data['data'][$heroName]['stats']['armorperlevel'],
                                            'spellblock' => $data['data'][$heroName]['stats']['spellblock'], 'spellblockperlevel' => $data['data'][$heroName]['stats']['spellblockperlevel'],
                                            'attackrange' => $data['data'][$heroName]['stats']['attackrange'], 'hpregen' => $data['data'][$heroName]['stats']['hpregen'],
                                            'hpregenperlevel' => $data['data'][$heroName]['stats']['hpregenperlevel'], 'mpregen' => $data['data'][$heroName]['stats']['mpregen'],
                                            'mpregenperlevel' => $data['data'][$heroName]['stats']['mpregenperlevel'], 'crit' => $data['data'][$heroName]['stats']['crit'],
                                            'cirtperlevel' => $data['data'][$heroName]['stats']['cirtperlevel'], 'attackdamage' => $data['data'][$heroName]['stats']['attackdamage'],
                                            'attackdamage' => $data['data'][$heroName]['stats']['attackdamage'], 'attackdamageperlevel' => $data['data'][$heroName]['stats']['attackdamageperlevel'],
                                            'attackspeed' => $data['data'][$heroName]['stats']['attackspeed'], 'attackspeedperlevel' => $data['data'][$heroName]['stats']['attackspeedperlevel'],
                                            'allytips' => $data['data'][$heroName]['allytips'][0], 'enemytips' => $data['data'][$heroName]['enemytips'][0],
                                            //版本Id
                                            'versionId' => $versionDetail['id'],'creater' => "default", 'createTime' => date("Y-m-d H:i:s",time()),
                                        ]);
                                }


                                //英雄技能
                                $spellsRes = $db->table('tbspells')->where(['heroId' => $data['data'][$heroName]['key'], 'versionId' => $versionDetail['id']])->find();
                                var_dump($spellsRes);
                                /*if (!empty($spellsRes)) {
                                    //更新
                                    $db->table('tbspells')->where(['id' => $res['id']], ['versionId' => $res['versionId']])->update([
                                        'cost' => serialize($data['data'][$heroName]['spells']['cost']), 'costburn' =>  $data['data'][$heroName]['spells']['costburn'],
                                        'cooldown' => $data['data'][$heroName]['spells']['cooldown'], 'cooldownburn' =>  $data['data'][$heroName]['spells']['cooldownburn'],
                                        //版本Id,创建人,创建时间
                                        'versionId' => $versionDetail['id'], 'updateMan' => "default", 'updateTime' => time(),
                                    ]);

                                }else{
                                    //添加
                                    $db->table('tbspells')->insert(
                                        [
                                            'cost' => serialize($data['data'][$heroName]['spells']['cost']), 'costburn' =>  $data['data'][$heroName]['spells']['costburn'],
                                            'cooldown' => $data['data'][$heroName]['spells']['cooldown'], 'cooldownburn' =>  $data['data'][$heroName]['spells']['cooldownburn'],
                                            //版本Id,创建人,创建时间
                                            'versionId' => $versionDetail['id'], 'creater' => "default", 'createTime' => time(),
                                        ]);
                                }*/

                            }

                        }else{
                            $this->ajaxError('没有导入数据，请导入数据');
                        }


                        try {
                            $db->begin();
                            //检查状态,如果是0->3,2->1
                            if(2==(int)$resStatus['status'])
                            {
                                $db->table('tbversion')->where(['versionNumber' => $versionNum])->update(['status' => 1]);
                            }else{
                                $db->table('tbversion')->where(['versionNumber' => $versionNum])->update(['status' => 3]);
                            }
                            $db->commit();
                            //更新成功后改变文件夹的名称(名称以版本号为命名)
                            $new_name = $savePath. 'jsonFiles/'.$versionNum;
                            if(file_exists($new_name)||!file_exists($savePath.$dir)){
                                $this->ajaxError("目标文件已存在或原文件不存在");
                            }else{
                                if(rename($savePath.'jsonFiles/'.date("Ymd"),$new_name)){
                                    $this->ajaxSuccess("更新到数据库成功");
                                }else{
                                    $this->ajaxError("文件夹重命名失败");
                                }
                            }

                        } catch (\Exception $e) {
                            $db->rollBack();
                            $this->ajaxSuccess("更新到数据库失败");
                        }
                    }
                }
            }else{
                //获取版本号
                $versionInfo = $db->table('tbversion')->where(['isCurrent' => 1])->find();

                $this->assign('id', $_GET['id']);
                $this->assign('versionInfo', $versionInfo['versionNumber']);
                $this->display("Admin/Version/switchVersion");
        }
    }

    /**
     * 更新数据库版本信息
     */
    public function updateVersion()
    {
        $db = Lib\Db\DbModel::init(); // 构造方法，线上自动切换

        if(IS_POST)
        {

            //获取数据的版本
            $versionNum = I('versionNum');

            //获取TombaJson版本
            $versionType = "TombaJson";

            //环境判断
            if (ENV == 'test' && ENVIRONMENT == 'NON_OA') {
                $savePath = APP.'upload/';
            } else {
                $savePath = UPLOADED_PATH;
            }

            $dir = empty($_GET['dir']) ? 'jsonFiles/'.date("Ymd")."/".$versionType.'/' : 'Uploads/' . $_GET['dir'];

            //读取Json文件里面的数据
            if(is_dir($savePath.$dir)){
                //判断是否有文件
                $fileList = my_scandir($savePath.$dir);

                //根据版本号查询出版本的主键Id
                $versionDetail = $db->table('tbversion')->where(['versionNumber' => $versionNum])->find();

                foreach ($fileList as $key=>$val)
                {
                    //skins.json(判断是否是skins.json)
                    if(strpos($val,"skins.json")!==FALSE)
                    {
                        // 从文件中读取数据到PHP变量
                        $json_string = file_get_contents($val);
                        // 用参数true把JSON字符串强制转成PHP数组
                        $skinsData = json_decode($json_string, true);
                        //var_dump("--------------皮肤-------------");
                        //var_dump($itemsData);
                        //var_dump("--------------皮肤结束---------");
                    }
                    //items.json
                    if(strpos($val,"items.json")!==FALSE)
                    {
                        // 从文件中读取数据到PHP变量
                        $json_string = file_get_contents($val);
                        // 用参数true把JSON字符串强制转成PHP数组
                        $itemsData = json_decode($json_string, true);
                        //var_dump("--------------道具-------------");
                        //var_dump($itemsData);
                        //var_dump("--------------道具结束---------");
                    }

                    //依次读取里面的内容
                    // 从文件中读取数据到PHP变量
                    $json_string = file_get_contents($val);
                    // 用参数true把JSON字符串强制转成PHP数组
                    $data = json_decode($json_string, true);

                    //英雄名称
                    //var_dump($data['title']);
                    //英雄称号
                    //var_dump($data['name']);
                    //英文名
                    //var_dump($data['alias']);
                    //英雄Id
                    //var_dump($data['id']);
                    //英雄定位
                    //var_dump($data['roles']);
                    //英雄故事
                    //var_dump($data['shortBio']);
                    //英雄被动技能
                    //var_dump($data['passive']['name']);
                    //英雄被动技能描述
                    //var_dump($data['passive']['description']);
                    //英雄被动技能图标
                    //var_dump($data['passive']['abilityVideoImagePath']);
                    //英雄被动技能视频
                    //var_dump($data['passive']['abilityVideoPath']);
                    //英雄主动技能
                    //遍历里面的内容
                    foreach ($data['spells'] as $key=>$val)
                    {
                        //快捷键
                        if($val['spellKey']=="q"){
                            $data['q']['name'] = $val['name'];
                            $data['q']['spellKey'] = $val['spellKey'];
                            $data['q']['description'] = $val['description'];
                            $data['q']['abilityIconPath'] = $val['abilityIconPath'];
                            $data['q']['abilityVideoPath'] = $val['abilityVideoPath'];
                            $data['q']['dynamicDescription'] = $val['dynamicDescription'];
                        }elseif($val['spellKey']=="w"){
                            $data['w']['name'] = $val['name'];
                            $data['w']['spellKey'] = $val['spellKey'];
                            $data['w']['description'] = $val['description'];
                            $data['w']['abilityIconPath'] = $val['abilityIconPath'];
                            $data['w']['abilityVideoPath'] = $val['abilityVideoPath'];
                            $data['w']['dynamicDescription'] = $val['dynamicDescription'];
                        }elseif($val['spellKey']=="e"){
                            $data['e']['name'] = $val['name'];
                            $data['e']['spellKey'] = $val['spellKey'];
                            $data['e']['description'] = $val['description'];
                            $data['e']['abilityIconPath'] = $val['abilityIconPath'];
                            $data['e']['abilityVideoPath'] = $val['abilityVideoPath'];
                            $data['e']['dynamicDescription'] = $val['dynamicDescription'];
                        }elseif($val['spellKey']=="r"){
                            $data['r']['name'] = $val['name'];
                            $data['r']['spellKey'] = $val['spellKey'];
                            $data['r']['description'] = $val['description'];
                            $data['r']['abilityIconPath'] = $val['abilityIconPath'];
                            $data['r']['abilityVideoPath'] = $val['abilityVideoPath'];
                            $data['r']['dynamicDescription'] = $val['dynamicDescription'];
                        }
                    }

                    //英雄皮肤
                    foreach ($data['skins'] as $key=>$val)
                    {
                        //$list5 = $db->table('uss')->where(['id' => 3050])->update(['num' => 1234]);
                        //更新到数据库(英雄Id,英雄名称,英雄称号,皮肤名称,皮肤Id,炫彩，炫彩皮肤从属,皮肤标记经典史诗传说等,皮肤描述)
                        $skillRes = $db->table('tbskins')->where(['versionId' => $versionDetail['id']])->update(['heroId' => $data['id'],'heroName' => $data['title'],
                            'heroTitle' => $data['name'],'name'=> $val['name'],'skinId' =>$val['id'],
                            'emblems' => $val['emblems'][0]['name'],'description' =>$val['description'],
                            'updateTime' => date("Y-m-d H:i:s",time()), 'updateMan' => "default"
                        ]);
                    }

                    //添加到数据库(英雄名称,英雄中文名,英雄称号,英雄Id,英雄定位,英雄简介，英雄阵营，版本Id)
                    $HeroRes = $db->table('tbhero')->where(['id'=>$data['id']],['versionId' => $versionDetail['id']])->update(
                        ['title' =>$data['title'], 'alias' =>$data['alias'],
                            'name'=>$data['name'], 'heroId'=>$data['id'],
                            'roles'=>$data['roles'][0], 'shortBio'=>$data['shortBio'],
                            'camp'=>"艾欧尼亚",
                            'updateTime' => date("Y-m-d H:i:s",time()),
                            'updateMan' => "default"
                        ]
                    );
                }

                //英雄道具
                if(!empty($itemsData))
                {
                    foreach ($itemsData as $key=>$val)
                    {
                        //道具名称
                        //var_dump($val['name']);
                        //道具Id
                        //var_dump($val['id']);
                        //道具图片
                        //var_dump($val['iconPath']);
                        //道具价格
                        //var_dump($val['price']);
                        //道具描述
                        //var_dump($val['description']);
                        //道具从属地图
                        //var_dump($val['mapStringIdInclusions']);
                        //适应英雄
                        //var_dump(1);
                        //道具标签
                        //var_dump("哈哈");
                        //道具所属类型
                        //var_dump("哈哈");

                        //添加到数据库()
                        $itemsRes = $db->table('tbitems')->where(['versionId' => $versionDetail['id']])->update(
                            ['name' =>$val['name'], 'itemId' =>$val['id'],
                                'iconPath'=>$val['iconPath'], 'price'=>$val['price'],
                                'description'=>$val['description'], 'mapId'=>"{1,2,3}",
                                'updateTime' => date("Y-m-d H:i:s",time()),
                                'updateMan' => "default"
                            ]
                        );
                    }
                }

            }else{
                $this->ajaxError('没有导入数据，请导入数据');
            }

            $this->ajaxSuccess("更新成功");

        }else{
            //获取版本号
            $versionInfo = $db->table('tbversion')->where(['isCurrent' => 1])->find();

            $this->assign('id', $_GET['id']);
            $this->assign('versionInfo', $versionInfo['versionNumber']);
            $this->display("Admin/Version/switchVersion");
        }
    }
}